package com.itHuangTao.tank.effects;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.dsl.components.Effect;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.texture.Texture;
import com.itHuangTao.tank.Config;

public class ShipEffect extends Effect {

    private Texture texture;

    public ShipEffect() {
        //轮船效果存在的时间为无穷大(改成20秒)
        super(Config.SHIP_TIME);
        texture = FXGL.texture("item/armed_ship.png");
    }

    //效果开始的时候
    @Override
    public void onStart(Entity entity) {
        //调整视图显示在坦克中间(加X，Y的偏移量)
        texture.setTranslateX(entity.getWidth()/2.0-texture.getWidth()/2.0);
        texture.setTranslateY(entity.getHeight()/2.0-texture.getHeight()/2.0);

        entity.getViewComponent().addChild(texture);
    }

    //效果结束的时候
    @Override
    public void onEnd(Entity entity) {
        entity.getViewComponent().removeChild(texture);
    }
}
